package com.jiayuge.server.common.converter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

/**
 * 功能: 日期转换
 *
 * @Program: yeb
 * @Date: 2021-11-26 09:40
 * @Author Jiayu.Yang
 */
@Component
public class DateConverter implements Converter<String, LocalDate> {

    @Override
    public LocalDate convert(String source) {
        try {
            return LocalDate.parse(source, DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.forLanguageTag("Asia/Shanghai")));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
